<?php

require_once('./API/DB/MySQL.class.php');

class Vinyl
{
    protected $artist;
    protected $title;
    protected $format;
    protected $pressing;
    protected $genre;
    protected $style;
    protected $releaseDate;
    protected $purchaseDate;
    protected $imageURL;

    public function __construct ($artist,$title,$format,$pressing,$genre,$style,$releaseDate,$purchaseDate,$imageURL)
    {
        $this->artist = $artist;
        $this->title = $title;
        $this->format = $format;
        $this->pressing = $pressing;
        $this->releaseDate = $releaseDate;
        $this->genre = $genre;
        $this->style = $style;
        $this->purchaseDate = $purchaseDate;
        $this->imageURL = $imageURL;

        $this->toDB();
    }

    protected function toDB()
    {
        $pdo = new MySQL();
        $pdo->insertVinyl($this->artist,$this->title,$this->format,$this->pressing,$this->genre,$this->style,$this->releaseDate,$this->purchaseDate,$this->imageURL);
    }

    public static function showAll()
    {
        $pdo = new MySQL();
        $vinyls = $pdo->selectVinyls();

        $numVinyls = count($vinyls);

        for($i = 0; $i <$numVinyls; $i++) {
            echo "<a href='#'>";
            echo "<div class='indexVinyls'>";

            echo "<img src='" .$vinyls[$i][9]. "' class='indexVinylsImage' />";
            echo "</br>" . $vinyls[$i][1];
            echo "</br>" . $vinyls[$i][2];
//            echo $vinyls[$i][];

            echo "</div>";
            echo "</a>";
        }
    }
}

Vinyl::showAll();